object binary_search {
  def main(args: Array[String]) {
    val my_array = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    println(binary_search(my_array, 5))
    println(binary_search(my_array, 15))
  }

  def binary_search(array: Array[Int], item: Int): Int = {
    var low: Int = 0
    var high: Int = array.length - 1
    while (low <= high) {
      val mid: Int = (low + high) / 2
      val guess: Int = array(mid)
      if (guess == item)
        return mid
      else if (guess > item)
        low = mid + 1
      else if (guess < item)
        high = mid - 1
    }
    return -1
  }
}